package org.uim.cricket.storage;

public class InputArgumentParser {
	
	private String[] args = null;
	
	private String analyzerDir = null;
	private boolean subDirs = false;
	private String sourceQueryFile = null;
	private boolean runQueries = false;
	private int limit = -1;
	private boolean queryExecuteOnly = false;
	
	public InputArgumentParser(String[] args) {
		this.args = args;
	}
	
	public void parse() throws Exception {
		if (args.length < 2) {
			throw new Exception ("Insufficient input arguments!");
		}
		
		int curr = 0;
		this.analyzerDir = args[curr++];
		
		if (args[curr].startsWith("-limit:")) {
			String cap  = args[curr++].substring(7).trim();
			this.limit = Integer.parseInt(cap);
		}
		
		if (args[curr].startsWith("-sd:")) {
			String cap = args[curr++].substring(4).trim();
			if (cap.equalsIgnoreCase("yes")) subDirs = true;
		} 

		if (curr >= args.length) throw new Exception ("Insufficient input arguments!");
		this.sourceQueryFile = args[curr++];
		
		if (curr >= args.length) return;
		if (args[curr].startsWith("-q:")) {
			String cap = args[curr++].substring(3).trim();
			if (cap.equalsIgnoreCase("yes")) this.runQueries = true;
		}
		
		if (curr >= args.length) return;
		if (args[curr].startsWith("-qexeconly:")) {
			String cap = args[curr++].substring(11).trim();
			if (cap.equalsIgnoreCase("yes")) this.queryExecuteOnly = true;
		}
		
	}

	public String[] getArgs() {
		return args;
	}

	public void setArgs(String[] args) {
		this.args = args;
	}

	public String getAnalyzerDir() {
		return analyzerDir;
	}

	public void setAnalyzerDir(String analyzerDir) {
		this.analyzerDir = analyzerDir;
	}

	public boolean isSubDirs() {
		return subDirs;
	}

	public void setSubDirs(boolean subDirs) {
		this.subDirs = subDirs;
	}

	public String getSourceQueryFile() {
		return sourceQueryFile;
	}

	public void setSourceQueryFile(String sourceQueryFile) {
		this.sourceQueryFile = sourceQueryFile;
	}

	public boolean isRunQueries() {
		return runQueries;
	}

	public void setRunQueries(boolean runQueries) {
		this.runQueries = runQueries;
	}
	
	public void setLimit(int limit) {
		this.limit = limit;
	}
	
	public int getLimit() {
		return limit;
	}
	
	public void setQueryExecuteOnly(boolean queryExecuteOnly) {
		this.queryExecuteOnly = queryExecuteOnly;
	}
	
	public boolean isQueryExecuteOnly() {
		return queryExecuteOnly;
	}
	
}
